clear all;

cd ..; cd ..; cd ..;
baseline=load('code_main_model\6_implied_w_r\computation_results\data.mat','credit','d');
credit=load('code_main_model_credit\6_implied_w_r\computation_results\data.mat','Z','adjust_backward','gl_backward','gk_backward','nmkt','pdf_B_forward','GDP','K','Y','chi','alpha','nu','psi',...
    'nb','ntheta','nz','gridb','gridtheta','gridz','nb_pdf','ntheta_pdf','gridb_pdf','gridtheta_pdf','period_trans');
cd 'code_figure_table\OA\Figure OA29';

mkt_bank86=find(baseline.d(1,:)==0);
mkt_nobank86=find(baseline.d(1,:)>0);

baseline.credit_allmkt=sum(baseline.credit,2);
credit.credit_allmkt=sum(credit.credit,2);

additional_credit_allmkt=baseline.credit_allmkt-credit.credit_allmkt;

baseline.credit_bank86mkt=sum(baseline.credit(:,mkt_bank86),2);
credit.credit_bank86mkt=sum(credit.credit(:,mkt_bank86),2);

additional_credit_bank86mkt=baseline.credit_bank86mkt-credit.credit_bank86mkt;

psi_pct_of_banked=additional_credit_bank86mkt./additional_credit_allmkt;
psi_pct_of_unbanked=1-psi_pct_of_banked;

psi_pct_of_banked=psi_pct_of_banked(2:11);
psi_pct_of_unbanked=psi_pct_of_unbanked(2:11);

save('credittobaseline.mat','psi_pct_of_banked','psi_pct_of_unbanked')